package com.yc.springmvc.controller;

import com.yc.springmvc.bean.Person;
import com.yc.springmvc.bean.Result;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
public class UserDao {

    @RequestMapping("reg")
    public Result reg(@Valid Person person,
                      Errors errors){
        if (errors.hasErrors()){
            return  new Result(0,"字段验证错误",errors.getAllErrors());
        }

        return new Result(1,"注册成功",person);
    }
}
